package com.boot.web.controller;

import java.util.Date;
import java.util.Map;

import com.boot.web.dao.GoodsCategoryDao;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.boot.communal.paging.InitPaging;
import com.boot.communal.response.ResponseServer;
import com.boot.web.entity.GoodsCategory;
import com.boot.web.service.GoodsCategoryService;

/**
 * 商品类别控制器
 * @author 【zhouJie】
 * @date 2021-09-28 17:55:04
 */
@RestController
@RequestMapping("/goodsCategory")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @Autowired
    private GoodsCategoryDao goodsCategoryDao;

    @PostMapping("/save")
    public ResponseServer save(GoodsCategory goodsCategory) {
        goodsCategory.setUpdateTime(new Date());
        return ResponseServer.success("添加成功", goodsCategoryService.save(goodsCategory));
    }

    @PutMapping("/update")
    public ResponseServer update(GoodsCategory goodsCategory) {
        goodsCategory.setUpdateTime(new Date());
        return ResponseServer.success("修改成功", goodsCategoryService.update(goodsCategory));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseServer delete(@PathVariable Integer id) {
        return ResponseServer.success("删除成功", goodsCategoryService.delete(id));
    }

    @DeleteMapping("/batchDelete/{ids}")
    public ResponseServer batchDelete(@PathVariable Integer[] ids) {
        return ResponseServer.success("批量删除成功", goodsCategoryService.batchDelete(ids));
    }

    @GetMapping("/getPageList")
    public ResponseServer getPageList(@RequestParam Map<String, Object> params) {
        InitPaging.init(params);
        return ResponseServer.success(new PageInfo(goodsCategoryService.getPageList(params)));
    }

    @GetMapping("/getAll")
    public ResponseServer getAll() {
        return ResponseServer.success(goodsCategoryService.getAll());
    }

    @GetMapping("/getAll2")
    public ResponseServer getAll2() {
        return ResponseServer.success(goodsCategoryDao.queryAll2());
    }

    @GetMapping("/getById/{id}")
    public ResponseServer getById(@PathVariable Integer id) {
        return ResponseServer.success(goodsCategoryService.getById(id));
    }

}
